﻿using Leeder.Logger;
using PickingGuide.Business;
using PickingGuide.Handle;
using PickingGuide.Model;
using PickingGuideForm;
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;

namespace ScanConfirmForm
{
    public partial class FrmSetup : Form
    {
        PickingGuideHandler pickingGuideHandler;
        QueueInfoBLL queueInfoBLL = new QueueInfoBLL();
        private LogOperate LogObj => Log.GetLogger(this.GetType());

        ProductionModelsBLL productionModelsBLL = new ProductionModelsBLL();
        PlcConnectBLL plcConnectBLL = new PlcConnectBLL();
        PlcAddresBLL plcAddresBLL = new PlcAddresBLL();
        PickingSetupBLL pickingSetupBLL = new PickingSetupBLL();
        PickingDetailBLL pickingDetailBLL = new PickingDetailBLL();
        RackSetupBLL rackSetupBLL = new RackSetupBLL();
        SystemSetupBLL systemSetupBLL = new SystemSetupBLL();
        PartsBLL partsBLL = new PartsBLL();

        SystemSetupModel systemSetupModel;
        PlcConnectModel plcConnect;

        int pageSize = 30;       //数据表每页默认行数
        public FrmSetup()
        {
            InitializeComponent();
            //全屏，覆盖任务栏
            if (this.WindowState == FormWindowState.Maximized)
            {
                this.WindowState = FormWindowState.Normal;
            }
            else
            {
                this.FormBorderStyle = FormBorderStyle.None;
                this.WindowState = FormWindowState.Maximized;
            }

            dgvCarTyp.ClearSelection();
            dgvCarTyp.AutoGenerateColumns = false;
            dgvCarTyp.ReadOnly = true;
            dgvCarTyp.AddColumn("车型名称", "ModelName");
            dgvCarTyp.AddColumn("车型代码", "ModelCode");

            dgvPlc.ClearSelection();
            dgvPlc.AutoGenerateColumns = false;
            dgvPlc.ReadOnly = true;
            dgvPlc.AddColumn("区块", "Area");
            dgvPlc.AddColumn("地址", "Address");
            dgvPlc.AddColumn("长度", "DataLength");
            dgvPlc.AddColumn("数据类型", "PlcDataType");
            dgvPlc.AddColumn("操作类型", "OperateType");
            dgvPlc.AddColumn("信号标识", "SignalMark");

            dgvRack.ClearSelection();
            dgvRack.AutoGenerateColumns = false;
            dgvRack.ReadOnly = true;
            dgvRack.AddColumn("货架名称", "Name");
            dgvRack.AddColumn("货架代码", "Code");
            dgvRack.AddColumn("货架类型", "RackType");
            //dgvRack.AddColumn("PLC地址", "PlcAddress");
            dgvRack.AddColumn("爱欧地址", "AioiAddress");
            dgvRack.AddColumn("IO卡输出口", "IoCarOutNum");
            dgvRack.AddColumn("IO卡输入口", "IoCarInNum");

            dgvPicking.ClearSelection();
            dgvPicking.AutoGenerateColumns = false;
            dgvPicking.ReadOnly = true;
            dgvPicking.AddColumn("拣货名称", "Name");
            dgvPicking.AddColumn("车型名称", "ModelName");
            dgvPicking.AddColumn("车型代号", "CarCode");
            dgvPicking.AddColumn("部品序号", "PartsNum");
            dgvPicking.AddColumn("部品代号", "Code");

            dgvPickingDetail.ClearSelection();
            dgvPickingDetail.AutoGenerateColumns = false;
            dgvPickingDetail.ReadOnly = true;
            dgvPickingDetail.AddColumn("拣货名称", "PickingID");
            dgvPickingDetail.AddColumn("货架", "RackID");

            dgvLocation.ClearSelection();
            dgvLocation.AutoGenerateColumns = false;
            //dgvLocation.ReadOnly = true;
            dgvLocation.AddColumn("车型", "CarModel");
            dgvLocation.AddColumn("连番", "Sequence");
            dgvLocation.AddColumn("VIN码", "VIN");
            dgvLocation.AddColumn("下发时间", "CreatedDate");

            dgvPartsCode.ClearSelection();
            dgvPartsCode.AutoGenerateColumns = false;
            dgvPartsCode.ReadOnly = true;
            dgvPartsCode.AddColumn("部品代号", "CarCode");
            dgvPartsCode.AddColumn("品番", "PartsCode");

            pickingGuideHandler = PickingGuideHandler.getInstance();

            //设置开始时间为三天前
            this.dpStartDate.Value = DateTime.Now.AddDays(-3);
            this.dpEndDate.Value = DateTime.Now;

            //设置分页控件每页数量
            uiPagination1.PageSize = pageSize;
            uiPagination1.Style = UIStyle.Blue;

            var frmSetups = pickingGuideHandler.SystemSetup.FrmSetup.Split(',');
            if(!frmSetups.Contains("1"))
                tabPage4.Parent = null;
            if (!frmSetups.Contains("2"))
                tabPage1.Parent = null;
            if (!frmSetups.Contains("3"))
                tabPage2.Parent = null;
            if (!frmSetups.Contains("4"))
                tabPage7.Parent = null;
            if (!frmSetups.Contains("5"))
                tabPage5.Parent = null;
            if (!frmSetups.Contains("6"))
                tabPage6.Parent = null;
            if (!frmSetups.Contains("7"))
                tabPage8.Parent = null;
            if (!frmSetups.Contains("8"))
                tabPage3.Parent = null;
            //if (!frmSetups.Contains("9"))
            //    tabPage9.Parent = null;
        }

        private void FrmSetup_Load(object sender, EventArgs e)
        {
            var carModelList = productionModelsBLL.GetModelAll();
            if (carModelList == null)
                carModelList = new List<ProductionModelsModel>();
            carModelList.Insert(0, new ProductionModelsModel { ModelName = "--ALL--", ModelCode = "--ALL--" });
            cbVehicleModel.DataSource = carModelList;
            cbVehicleModel.DisplayMember = "ModelName";
            cbVehicleModel.ValueMember = "ModelName";
            cbVehicleModel.SelectedIndex = 0;

            //cbCarCode.DataSource = carModelList;
            //cbCarCode.DisplayMember = "ModelCode";
            //cbCarCode.ValueMember = "ModelCode";
            //cbCarCode.SelectedIndex = 0;

            var frmSetups = pickingGuideHandler.SystemSetup.FrmSetup.Split(',');
            if (frmSetups.Contains("1"))
                Search_Location();
            if (frmSetups.Contains("2"))
                Search_CarType();
            if (frmSetups.Contains("3"))
                Search_Plc();
            if (frmSetups.Contains("4"))
                Search_Rack();
            if (frmSetups.Contains("5"))
                Search_Picking();
            if (frmSetups.Contains("6"))
                Search_PickingDetail();
            if (frmSetups.Contains("7"))
                Search_Parts();
            if (frmSetups.Contains("8"))
                Search_Other();

            //Search_Location();
            //Search_CarType();
            //Search_Parts();
            //Search_PartsEquate();
            //Search_Other();
        }

        /// <summary>
        /// 查询--队列定位
        /// </summary>
        private void Search_Location()
        {
            DateTime? startDate = dpStartDate.Value;
            DateTime? endDate = dpEndDate.Value;
            ////设置分页控件总数
            uiPagination1.TotalCount = queueInfoBLL.GetModelCountByWhere(cbVehicleModel.SelectedValue == null ? "" : cbVehicleModel.SelectedValue.ToString(), txtSequence.Text, txtVIN.Text, startDate, endDate);
            uiPagination1_PageChanged(null, null, 1, pageSize);
        }

        public void Dgv_Cells(ref UIDataGridView dgv)
        {
            if (dgv.Rows.Count > 0)
                dgv.Rows[0].Selected = false;

            foreach (DataGridViewRow item in dgv.Rows)
            {
                var model = item.DataBoundItem as QueueInfoModel;
                if (string.IsNullOrEmpty(model.Status))
                {
                    item.DefaultCellStyle.BackColor = Color.White;
                }
                else if (model.Status == "pass")
                {
                    item.DefaultCellStyle.BackColor = Color.LightGray;
                }
                else if (model.Status == "ok")
                {
                    item.DefaultCellStyle.BackColor = Color.LightGreen;
                }
            }
        }

        /// <summary>
        /// 查询--车型
        /// </summary>
        private void Search_CarType()
        {
            this.Invoke(new MethodInvoker(() =>
            {
                dgvCarTyp.DataSource = null;
                dgvCarTyp.DataSource = productionModelsBLL.GetModelAll();
            }));
        }

        /// <summary>
        /// 查询--PLC地址配置
        /// </summary>
        private void Search_Plc()
        {
            this.Invoke(new MethodInvoker(() =>
            {
                dgvPlc.DataSource = null;
                dgvPlc.DataSource = plcAddresBLL.GetModelAll();
            }));
        }

        /// <summary>
        /// 查询--货架
        /// </summary>
        private void Search_Rack()
        {
            this.Invoke(new MethodInvoker(() =>
            {
                dgvRack.DataSource = null;
                dgvRack.DataSource = rackSetupBLL.GetModelAll();
            }));
        }

        /// <summary>
        /// 查询--品番等同
        /// </summary>
        private void Search_Picking()
        {
            this.Invoke(new MethodInvoker(() =>
            {
                dgvPicking.DataSource = null;
                dgvPicking.DataSource = pickingSetupBLL.GetModelAll();
            }));
        }

        /// <summary>
        /// 查询--拣货明细
        /// </summary>
        private void Search_PickingDetail()
        {
            this.Invoke(new MethodInvoker(() =>
            {
                dgvPickingDetail.DataSource = null;
                dgvPickingDetail.DataSource = pickingDetailBLL.GetModelAll();
            }));
        }

        /// <summary>
        /// 查询--其他
        /// </summary>
        private void Search_Other()
        {
            systemSetupModel = systemSetupBLL.GetModel();
            plcConnect = plcConnectBLL.GetModel();
            txtQueueLength.Text = systemSetupModel.QueueLength.ToString();
            txtPartsQty.Text = systemSetupModel.PartsQty.ToString();
            txtIoCardCom.Text = systemSetupModel.IoCardCom;
            txtSystemName.Text = systemSetupModel.SystemName;

            cbIsPartsCheck.SelectedIndex = systemSetupModel.IsPartsCheck ? 1 : 0;
            cbRackCommuniType.SelectedIndex = systemSetupModel.RackCommuniType;
            cbPlcIsOpen.SelectedIndex = systemSetupModel.PlcIsOpen ? 1 : 0;
            cbIoCardIsOpen.SelectedIndex = systemSetupModel.IoCardIsOpen ? 1 : 0;
            cbAioiIsOpen.SelectedIndex = systemSetupModel.AioiIsOpen ? 1 : 0;


            if (plcConnect == null)
                return;
            txtPlcIP.Text = plcConnect.IP.ToString();
            txtPlcPort.Text = plcConnect.Port.ToString();
        }

        /// <summary>
        /// 查询--部品配置
        /// </summary>
        private void Search_Parts()
        {
            this.Invoke(new MethodInvoker(() =>
            {
                dgvPartsCode.DataSource = null;
                dgvPartsCode.DataSource = partsBLL.GetModelAll();
            }));
        }

        private void uiPagination1_PageChanged(object sender, object pagingSource, int pageIndex, int count)
        {
            try
            {
                DateTime? startDate = dpStartDate.Value;
                DateTime? endDate = dpEndDate.Value;
                dgvLocation.DataSource = queueInfoBLL.GetModelListByWhere(cbVehicleModel.SelectedValue == null ? "" : cbVehicleModel.SelectedValue.ToString(), txtSequence.Text, txtVIN.Text, startDate, endDate, pageIndex, count);
                Dgv_Cells(ref dgvLocation);
                dgvLocation.Refresh();
            }
            catch (Exception ex)
            {
                LogObj.Error(ex.Message);
            }
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            Search_Location();
        }

        private void btnLocation_Click(object sender, EventArgs e)
        {
            if(!pickingGuideHandler.IsSuspend && pickingGuideHandler.SystemSetup.SuspendActivate)
            {
                MessageBox.Show("请先再主页点击作业暂停后才允许定位！");
                return;
            }
            var model = dgvLocation.CurrentRow.DataBoundItem as QueueInfoModel;
            if (model == null)
            {
                MessageBox.Show("请先选择要定位的行！");
                return;
            }else
            {
                MessageBoxButtons mess = MessageBoxButtons.OKCancel;
                DialogResult dr = MessageBox.Show("是否确定要定位到连番"+ model.Sequence+"的队列？", "提示", mess);
                if (dr == DialogResult.OK)
                {
                    pickingGuideHandler.SetLocation(model);
                    //Search_Location();
                    this.Close();
                }
            }
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button11_Click(object sender, EventArgs e)
        {
            systemSetupModel.QueueLength = int.Parse(txtQueueLength.Text);
            systemSetupModel.PartsQty = int.Parse(txtPartsQty.Text);
            systemSetupModel.SystemName = txtSystemName.Text;

            systemSetupModel.IoCardCom = txtIoCardCom.Text;
            systemSetupModel.IsPartsCheck = Convert.ToBoolean(cbIsPartsCheck.SelectedIndex);
            systemSetupModel.RackCommuniType = cbRackCommuniType.SelectedIndex;
            systemSetupModel.PlcIsOpen = Convert.ToBoolean(cbPlcIsOpen.SelectedIndex);
            systemSetupModel.IoCardIsOpen = Convert.ToBoolean(cbIoCardIsOpen.SelectedIndex);
            systemSetupModel.AioiIsOpen = Convert.ToBoolean(cbAioiIsOpen.SelectedIndex);

            if (plcConnect == null)
                plcConnect = new PlcConnectModel();

            plcConnect.IP = txtPlcIP.Text;
            plcConnect.Port = int.Parse(txtPlcPort.Text);

            var result = systemSetupBLL.Update(systemSetupModel);
            if(result.IsSuccess)
            {
                //MessageBox.Show("保存成功！");
            }else
            {
                MessageBox.Show("队列长度保存失败！");
            }

            if(plcConnect.ID == 0)
            {
                var result2 = plcConnectBLL.Add(plcConnect);
                if (result2.IsSuccess)
                {
                    MessageBox.Show("保存完成！");
                }
                else
                {
                    MessageBox.Show("PLC连接保存失败！");
                }
            }
            else
            {
                var result2 = plcConnectBLL.Update(plcConnect);
                if (result2.IsSuccess)
                {
                    MessageBox.Show("保存完成！");
                }
                else
                {
                    MessageBox.Show("PLC连接保存失败！");
                }
            }
        }

        private void btnCarType_Search_Click(object sender, EventArgs e)
        {
            Search_CarType();
        }

        private void btnCarType_Add_Click(object sender, EventArgs e)
        {
            FrmCarTypeSet frm = new FrmCarTypeSet();
            frm.RefreshUiEvent += Search_CarType;
            frm.Show();
        }

        private void btnCarType_Update_Click(object sender, EventArgs e)
        {
            var model = dgvCarTyp.CurrentRow.DataBoundItem as ProductionModelsModel;
            if (model == null)
            {
                MessageBox.Show("请先选择要修改的车型！");
                return;
            }
            else
            {
                FrmCarTypeSet frm = new FrmCarTypeSet(model);
                frm.RefreshUiEvent += Search_CarType;
                frm.Show();
            }
        }

        private void btnCarType_Del_Click(object sender, EventArgs e)
        {
            var model = dgvCarTyp.CurrentRow.DataBoundItem as ProductionModelsModel;
            if (model == null)
            {
                MessageBox.Show("请先选择要删除的车型！");
                return;
            }
            else
            {
                MessageBoxButtons mess = MessageBoxButtons.OKCancel;
                DialogResult dr = MessageBox.Show("是否删除车型" + model.ModelName + "吗？", "提示", mess);
                if (dr == DialogResult.OK)
                {
                    productionModelsBLL.Delete(model);
                    Search_CarType();
                }
            }
        }

        private void btnPlcAddres_Search_Click(object sender, EventArgs e)
        {
            Search_Plc();
        }

        private void btnPlcAddres_Add_Click(object sender, EventArgs e)
        {
            FrmPlcAddresSet frm = new FrmPlcAddresSet();
            frm.RefreshUiEvent += Search_Plc;
            frm.Show();
        }

        private void btnPlcAddres_Update_Click(object sender, EventArgs e)
        {
            var model = dgvPlc.CurrentRow.DataBoundItem as PlcAddresModel;
            if (model == null)
            {
                MessageBox.Show("请先选择要修改的地址！");
                return;
            }
            else
            {
                FrmPlcAddresSet frm = new FrmPlcAddresSet(model);
                frm.RefreshUiEvent += Search_Plc;
                frm.Show();
            }
        }

        private void btnPlcAddres_Del_Click(object sender, EventArgs e)
        {
            var model = dgvPlc.CurrentRow.DataBoundItem as PlcAddresModel;
            if (model == null)
            {
                MessageBox.Show("请先选择要删除的地址！");
                return;
            }
            else
            {
                MessageBoxButtons mess = MessageBoxButtons.OKCancel;
                DialogResult dr = MessageBox.Show("是否删除地址" + model.Address + "吗？", "提示", mess);
                if (dr == DialogResult.OK)
                {
                    plcAddresBLL.Delete(model);
                    Search_Plc();
                }
            }
        }

        private void btnPicking_Add_Click(object sender, EventArgs e)
        {
            FrmPickingSet frm = new FrmPickingSet();
            frm.RefreshUiEvent += Search_Picking;
            frm.Show();
        }

        private void btnPicking_Update_Click(object sender, EventArgs e)
        {
            var model = dgvPicking.CurrentRow.DataBoundItem as PickingSetupModel;
            if (model == null)
            {
                MessageBox.Show("请先选择要修改的拣货配置！");
                return;
            }
            else
            {
                FrmPickingSet frm = new FrmPickingSet(model);
                frm.RefreshUiEvent += Search_Picking;
                frm.Show();
            }
        }

        private void btnPicking_Search_Click(object sender, EventArgs e)
        {
            Search_Picking();
        }

        private void btnPicking_Delete_Click(object sender, EventArgs e)
        {
            var model = dgvPicking.CurrentRow.DataBoundItem as PickingSetupModel;
            if (model == null)
            {
                MessageBox.Show("请先选择要删除的拣货配置！");
                return;
            }
            else
            {
                MessageBoxButtons mess = MessageBoxButtons.OKCancel;
                DialogResult dr = MessageBox.Show("是否删除拣货配置" + model.Code + "吗？", "提示", mess);
                if (dr == DialogResult.OK)
                {
                    pickingSetupBLL.Delete(model);
                    Search_Picking();
                }
            }
        }

        private void btnPartsEquate_Close_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnRack_Search_Click(object sender, EventArgs e)
        {
            Search_Rack();
        }

        private void btnRack_Add_Click(object sender, EventArgs e)
        {
            FrmRackSet frm = new FrmRackSet();
            frm.RefreshUiEvent += Search_Rack;
            frm.Show();
        }

        private void btnRack_Update_Click(object sender, EventArgs e)
        {
            var model = dgvRack.CurrentRow.DataBoundItem as RackSetupModel;
            if (model == null)
            {
                MessageBox.Show("请先选择要修改的货架！");
                return;
            }
            else
            {
                FrmRackSet frm = new FrmRackSet(model);
                frm.RefreshUiEvent += Search_Rack;
                frm.Show();
            }
        }

        private void btnRack_Del_Click(object sender, EventArgs e)
        {
            var model = dgvRack.CurrentRow.DataBoundItem as RackSetupModel;
            if (model == null)
            {
                MessageBox.Show("请先选择要删除的货架！");
                return;
            }
            else
            {
                MessageBoxButtons mess = MessageBoxButtons.OKCancel;
                DialogResult dr = MessageBox.Show("是否删除货架" + model.Name + "吗？", "提示", mess);
                if (dr == DialogResult.OK)
                {
                    rackSetupBLL.Delete(model);
                    Search_Rack();
                }
            }
        }

        private void btnPickingDetail_Search_Click(object sender, EventArgs e)
        {
            Search_PickingDetail();
        }

        private void btnPickingDetail_Add_Click(object sender, EventArgs e)
        {
            FrmPickingDetailSet frm = new FrmPickingDetailSet();
            frm.RefreshUiEvent += Search_PickingDetail;
            frm.Show();
        }

        private void btnPickingDetail_Update_Click(object sender, EventArgs e)
        {
            var model = dgvPickingDetail.CurrentRow.DataBoundItem as PickingDetailModel;
            if (model == null)
            {
                MessageBox.Show("请先选择要修改的拣货明细！");
                return;
            }
            else
            {
                FrmPickingDetailSet frm = new FrmPickingDetailSet(model);
                frm.RefreshUiEvent += Search_PickingDetail;
                frm.Show();
            }
        }

        private void btnPickingDetail_Del_Click(object sender, EventArgs e)
        {
            var model = dgvPickingDetail.CurrentRow.DataBoundItem as PickingDetailModel;
            if (model == null)
            {
                MessageBox.Show("请先选择要删除的拣货明细！");
                return;
            }
            else
            {
                MessageBoxButtons mess = MessageBoxButtons.OKCancel;
                DialogResult dr = MessageBox.Show("是否删除该拣货明细？", "提示", mess);
                if (dr == DialogResult.OK)
                {
                    pickingDetailBLL.Delete(model);
                    Search_PickingDetail();
                }
            }
        }

        private void btnPickingDetail_Close_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void dgvRack_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            //if (e.ColumnIndex == 3)
            //{
            //    e.FormattingApplied = true;
            //    DataGridViewRow row = dgvRack.Rows[e.RowIndex];
            //    if (row != null)
            //    {
            //        var id = long.Parse(row.Cells[e.ColumnIndex].Value.ToString());
            //        var addres = plcAddresBLL.GetModel(id);
            //        e.Value = string.Format("{0}",
            //          addres.Area+addres.Address);
            //    }
            //}
        }

        private void dgvPickingDetail_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            if (e.ColumnIndex == 0)
            {
                e.FormattingApplied = true;
                DataGridViewRow row = dgvPickingDetail.Rows[e.RowIndex];
                if (row != null)
                {
                    var id = long.Parse(row.Cells[e.ColumnIndex].Value.ToString());
                    var pickingSetup = pickingSetupBLL.GetModel(id);
                    e.Value = string.Format("{0}",
                      pickingSetup.Name);
                }
            }
            else if (e.ColumnIndex == 1)
            {
                e.FormattingApplied = true;
                DataGridViewRow row = dgvPickingDetail.Rows[e.RowIndex];
                if (row != null)
                {
                    var id = long.Parse(row.Cells[e.ColumnIndex].Value.ToString());
                    var rack = rackSetupBLL.GetModel(id);
                    e.Value = string.Format("{0}",
                      rack.Name);
                }
            }
        }

        private void btnRack_Close_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnPartsCode_Search_Click(object sender, EventArgs e)
        {
            Search_Parts();
        }

        private void btnPartsCode_Add_Click(object sender, EventArgs e)
        {

            FrmPartsCodeSet frm = new FrmPartsCodeSet();
            frm.RefreshUiEvent += Search_Parts;
            frm.Show();
        }

        private void btnPartsCode_Updadte_Click(object sender, EventArgs e)
        {
            var model = dgvPartsCode.CurrentRow.DataBoundItem as PartsModel;
            if (model == null)
            {
                MessageBox.Show("请先选择要修改的品番！");
                return;
            }
            else
            {
                FrmPartsCodeSet frm = new FrmPartsCodeSet(model);
                frm.RefreshUiEvent += Search_Parts;
                frm.Show();
            }
        }

        private void btnPartsCode_Del_Click(object sender, EventArgs e)
        {
            var model = dgvPartsCode.CurrentRow.DataBoundItem as PartsModel;
            if (model == null)
            {
                MessageBox.Show("请先选择要删除的品番！");
                return;
            }
            else
            {
                MessageBoxButtons mess = MessageBoxButtons.OKCancel;
                DialogResult dr = MessageBox.Show("是否删除品番" + model.PartsCode + "吗？", "提示", mess);
                if (dr == DialogResult.OK)
                {
                    partsBLL.Delete(model);
                    Search_Parts();
                }
            }
        }

        private void btnPartsCode_Close_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
